//**** Alpha Numeric functions

#import <string.h>
#import "alphanum.h"

//* itoa: convert num to characters in str
void itoa(int num, char str[])
{
	int index, sign;

	if ((sign = num) < 0)	//** record sign
		num = -num;			//** make num positive

	index = 0;
	do {		//** generate digits in reverse order
		str[index++] = num % 10 + '0';	//** get next digit
	} while ((num /= 10) > 0);		//** delete it

	if (sign < 0)
		str[index++] = '-';
	str[index] = '\0';

	reverse(str);
}

//** reverse: reverse string str in place
void reverse(char str[])
{
	int c, index, j;

	for (index=0, j=strlen(str)-1; index<j; index++, j--) {
		c = str[index];
		str[index] = str[j];
		str[j] = c;
	}
}
